package edu.guigu.todolist.todo.model;


import java.util.ArrayList;
import java.util.List;

import edu.guigu.todolist.todo.model.TodoModel;
import edu.guigu.todolist.todo.model.info.TodoInfo;

public class TodoModelImpl implements TodoModel {

    private static TodoModelImpl instance = new TodoModelImpl();

    private TodoModelImpl() {
    }
    public static TodoModelImpl getInstance() {
        return instance;
    }

    private List<TodoInfo> todoInfoList = new ArrayList<TodoInfo>();

    @Override
    public void requestTodoData(Callback callback) {
        todoInfoList.clear();
        for (int i = 0; i < 5; i++) {
            todoInfoList.add(new TodoInfo("吃饭"));
            todoInfoList.add(new TodoInfo("睡觉"));
            todoInfoList.add(new TodoInfo("打豆豆"));
        }
        callback.onSuccess(todoInfoList,todoInfoList.size()-1);
    }

    @Override
    public void addTodoData(TodoInfo todoInfo, Callback callback) {
        todoInfoList.add(todoInfo);
        callback.onSuccess(todoInfoList,todoInfoList.size()-1);
    }

    @Override
    public void delTodoData(int position, Callback callback) {
        todoInfoList.remove(position);
        callback.onSuccess(todoInfoList,position);
    }
}
